package com.yax.mickey.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yax.mickey.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author yax
* @description 针对表【order(订单信息表)】的数据库操作Mapper
* @createDate 2024-05-27 09:03:30
* @Entity com.yax.mickey.entity.Order
*/
@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    @Select("select * from `order` where user_id = #{userId}")
    List<Order> getOrdersByUserId(int userId);

    @Select("select * from `order` where order_id = #{orderId}")
    Order getOrdersByOrderId(int orderId);

    @Insert("insert into `order` (order_id, user_id, total_amount, order_time, order_status) \n" +
            "values (#{orderId}, #{userId}, #{totalAmount}, NOW(), #{orderStatus});")
    Integer addOrders(Order order);

    @Update("update `order` set total_amount = #{totalAmount}, order_time = NOW(), order_status = #{orderStatus} where order_id = #{orderId}")
    void updateOrders(Order order);

    @Delete("delete from `order` where order_id = #{orderId}")
    void deleteOrders(Order order);
}